import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/package/help/package_help.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_tabBar_scrollView.dart';
import 'package:honeypotflutter/publicBussine/bussine_image.dart';
import '../package_list/view.dart';
import '../package_search/view.dart';
import 'logic.dart';

class PackagePage extends StatefulWidget {
  const PackagePage({Key? key}) : super(key: key);

  @override
  State<PackagePage> createState() => _PackagePageState();
}

class _PackagePageState extends State<PackagePage> {
  final PackageLogic logic = Get.put(PackageLogic());

  /*
  * 去搜索
  * */
  _pushToSearch() async {
    try {
      bool? isOperate = await Get.to<bool>(PackageSearchPage());
      if (isOperate != null && isOperate == true) {
        logic.waitPackageController.requestRefresh();
        logic.retentionPackageController.requestRefresh();
      }
    } catch (e) {}
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: HLAppBar(navigationTitle: "包裹查询", actions: [
        IconButton(
            onPressed: _pushToSearch,
            icon: Image.asset(
              MGImage.image("public_search", type: ImagePathType.public),
              width: 20,
            ))
      ]),
      body: HLTabBarScrollView(
        mens: ["待取件", "滞留件", "已取件"],
        children: [
          PackageListPage(
              type: PackageType.waitPackage,
              refreshController: logic.waitPackageController,
              recallPackageAction: () {
                logic.waitPackageController.requestRefresh();
                logic.retentionPackageController.requestRefresh();
                logic.acquiredPackageController.requestRefresh();
              },
              modifyPhoneAction: () {
                logic.retentionPackageController.requestRefresh();
              }),
          PackageListPage(
              type: PackageType.retentionPackage,
              refreshController: logic.retentionPackageController,
              recallPackageAction: () {
                logic.waitPackageController.requestRefresh();
                logic.retentionPackageController.requestRefresh();
                logic.acquiredPackageController.requestRefresh();
              },
              modifyPhoneAction: () {
                logic.waitPackageController.requestRefresh();
              }),
          PackageListPage(
            type: PackageType.acquiredPackage,
            refreshController: logic.acquiredPackageController,
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<PackageLogic>();
    super.dispose();
  }
}
